package patterns.chain;

import System.Task.Task;
import patterns.command.TaskStatus;

public class LowFuelHandler implements EmergencyHandler {
    private EmergencyHandler nextHandler;

    @Override
    public void setNextHandler(EmergencyHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleRequest(String emergencyType, Task task, String details) {
        if ("LOW_FUEL".equals(emergencyType)) {
            System.out.println("[紧急处理] 低油量警报 - 任务: " + task.getTaskId());
            task.addCommand("低油量警报: " + details);

            // 自动发送指令到最近的加油站
            task.addCommand("已规划到最近加油站的路径");

            // 暂停当前任务
            if (task.getStatus() == TaskStatus.EXECUTING) {
                task.pause();
                task.addCommand("任务因低油量暂停");
            }
        } else if (nextHandler != null) {
            nextHandler.handleRequest(emergencyType, task, details);
        }
    }
}
